

public class TuitionLoan {

    public static void main(String[] args) {

        double totalTuition = totalTuitionAmount();
        System.out.println("Total tuition amount for 4 year is: $" + totalTuitionAmount());
        System.out.println("The count of months for question 2 is " + totalMonthFromQuestionTwo(totalTuition));
        System.out.println("The count of months for question 3 is " + totalMonthFromQuestionThree(totalTuition));
    }


    private static double totalTuitionAmount() {
        double totalTuition = 0;
        double start = 10000;
        for (int i = 0; i < 4; i++) {
            totalTuition += start;
            start = start * 1.05;
        }
        return totalTuition;
    }


    private static int totalMonthFromQuestionTwo(double totalTuition) {
        return (int) (totalTuition / (totalTuition * 0.02));
    }

    private static int totalMonthFromQuestionThree(double totalTuition) {
        int month = 0;
        double payPerMonth = totalTuition * 0.02;
        while (true) {
            if (totalTuition <= 0) {
                break;
            }

            totalTuition -= payPerMonth;
            totalTuition = totalTuition * (1 + 0.01);
            month++;
        }
        return month;
    }

}
